package cn.imu.appdevexperiment2020._2activity.adapter;


import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import java.util.List;

import cn.imu.appdevexperiment2020.R;
import cn.imu.appdevexperiment2020._2activity.bean.Fruit;

/**
 * 描述:
 *
 * @author chenconghua
 * @version 1.0
 * @create 2022-11-05 18:22
 */
public class FruitAdapter extends ArrayAdapter<Fruit> {
   private int resoutceId;
   public FruitAdapter( Context context, int textViewResourceId, @NonNull List<Fruit> objects) {
      super(context, textViewResourceId, objects);
      resoutceId=textViewResourceId;
   }

   @NonNull
   @Override
   public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
      Fruit fruit = getItem(position);
      View view= LayoutInflater.from(getContext()).inflate(resoutceId,parent,false);
      ImageView fruitImage = (ImageView) view.findViewById(R.id.fruit_image);
      TextView fruitName=(TextView) view.findViewById(R.id.fruit_name);
      fruitImage.setImageResource(fruit.getImageId());
      fruitName.setText(fruit.getName());

      return view;
   }
}
